<?php
@session_start();
$login = true;
		if(!empty($_POST)){
			require("conn.php");
			$username=$_POST["username"];
			$password=$_POST["password"];
			$st="select * from tbluser where username='$username' and password=md5('$password')";
			
			$kq=mysql_query($st);
			
			$nr=mysql_num_rows($kq);
			
			$row=mysql_fetch_assoc($kq);
			if($nr>0)
			{			
			            $_SESSION["UserID"] = $row['id'];	
						$_SESSION["User"] = $username;
					    $_SESSION["Permit"]=$row['permission'];
					    $_SESSION["ArraySec"]=$row['section_ids'];
						
			?>
						<script language="javascript">
					
							window.location="index.php";
						
						</script>
			<?php
			
			}
			else
			{
			
					$login = false;
			}
		} 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SDDS-Admin</title>

<link rel="stylesheet" type="text/css" href="css/login.css"></link>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	
	
	$("#btnLogin").click(function (){
		var frm= document.frmLogin;
		var username = frm.username.value;
		var password = frm.password.value;
		if(username==""){
			alert("Xin hãy điền tên đăng nhập");
		}else if(password==""){
			alert("Thiếu mật khẩu!");	
		}else{
			frm.submit();
		}
			
	});

		
});

</script>
</head>
<body>
	
	<div id="page">
		
		
		<form action="" method="post" name="frmLogin">
			<h2>Administrator Login</h2>
			<?php if(!$login){
			echo "<div id='error'>Tên đăng nhập hoặc mật khẩu không đúng!</div>";
			}?>
			<div id="logo">
				
			</div>
			<div id="form">
				<div class="row">
					<label>Username:</label><input type="text" name="username" size="20"></input>
				</div>
				<div class="row">
					<label>Password:</label><input type="password" name="password" size="20"></input>
				</div>
				<div class="row">
					<input type="button" name="btnLogin" value="Login" id="btnLogin"></input>
				</div>
			</div>
		</form>
	</div>
</body>
</html>

